/*

	ATMEGA PIN  |  74xx595 PIN
	5 SS(PB4) 	|  12 ST_CP
	6 MOSI(PB5)	|  14 DS
	8 SCK(PB7)	|  11 SH_CP
				|  10 /MR -> Vcc
				|  13 /OE -> GND
				|

*/




#include <avr/io.h>

#include <util/delay.h>

#define DDR_SPI DDRB
#define DD_MOSI PB5
#define DD_SCK PB7
#define DD_SS PB4


void SPI_MasterInit(void)
{
/* Set MOSI and SCK output, all others input */
DDR_SPI = (1<<DD_MOSI)|(1<<DD_SCK)|(1<<DD_SS);
/* Enable SPI, Master, set clock rate fck/16 */
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);
}
void SPI_MasterTransmit(char cData)
{
/* Start transmission */
SPDR = cData;
/* Wait for transmission complete */
while(!(SPSR & (1<<SPIF)))
;
}

void funct(void){
PORTB |= _BV(PB4);
		SPI_MasterTransmit(0x01);
		PORTB &= !(_BV(PB4));
		_delay_ms(1);
}

void funct2(void){
PORTB |= _BV(PB4);
		SPI_MasterTransmit(0x02);
		PORTB &= !(_BV(PB4));
		_delay_ms(1);
}
		
		
void funct3(void){
PORTB |= _BV(PB4);
		SPI_MasterTransmit(0x04);
		PORTB &= !(_BV(PB4));
		_delay_ms(1);
}
void delay(){

int i;
for(i=0;i<1000;i++) _delay_ms(1);
}
int main(void){
	
	
     SPI_MasterInit();
		PORTB = 0x00;		//initialize Port B to zero
	
	funct();
		delay();
		//funct();//funct();funct();
		funct2();
		delay();
		funct3();
		delay();
		
		funct2();
    while(1){
	
		
    }
    return 0;
}
